const cloud = require('wx-server-sdk')
const mysql = require('mysql2/promise')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

// 数据库配置
const dbConfig = {
  host: 'your_host',
  user: 'your_username',
  password: 'your_password',
  database: 'your_database'
}

exports.main = async (event, context) => {
  try {
    // 创建数据库连接
    const connection = await mysql.createConnection(dbConfig)
    
    // 执行SQL查询
    const [rows] = await connection.execute('SELECT * FROM your_table')
    
    // 关闭连接
    await connection.end()
    
    return {
      success: true,
      data: rows
    }
  } catch (error) {
    return {
      success: false,
      error: error.message
    }
  }
} 